﻿var ProcessBook = function () {
    var that = this;
    this.doAction = function (state) {
        if (state.action == "GetBookList") {
            $.ajax({
                url: serverURL,
                data: state,
                success: function (d) {
                    that.showAllBooks($("#book_list"), eval(d), false);
                }
            });
        }
        if (state.action == "getSinglePersonInfo") {
            $.ajax({
                url: serverURL,
                data: state.otherKey,
                success: function (d) {
                    that.renderSinglePerson(eval(d));
                }
            });
        }
    }

    this.getAllBooks = function () {

    }

    this.getBooksByPersonId = function (id) {

    }

    this.showAllBooks = function (container,d,editTag) {
        $(container).html("");
        var showtag = editTag ? "display" : "none";
        var html = "<table class='tab'>";
        html += "<tr><td>Id</td><td>Name</td><td>money</td><td style='display:" + showtag + "'>edit</td></tr>";
        for (var i = 0; i < d.length; i++) {
            html += "<tr>";
            html += "<td>" + d[i].id + "</td>";
            html += "<td>" + d[i].name + "</td>";
            html += "<td>" + d[i].money + "</td>";
            html += "<td style='display:" + showtag + "'><a tag='edit' id='" + d[i].id + "'>Edit</a><a tag='del' id='" + d[i].id + "'>Delete</a></td>";
            html += "</tr>";
        }
        html += "</table>";
        $(container).append($(html));
    }
}